import 'package:logger/logger.dart';
import 'package:flutter/material.dart';

final logger = Logger(
  printer: PrettyPrinter(
    methodCount: 2,
    errorMethodCount: 8,
    lineLength: 120,
    colors: true,
    printEmojis: true,
    dateTimeFormat: DateTimeFormat.onlyTimeAndSinceStart,
  ),
);

class MyFilter extends LogFilter {
  @override
  bool shouldLog(LogEvent event) {
    return true;
  }
}

class MyPrinter extends LogPrinter {
  @override
  List<String> log(LogEvent event) {
    return [event.message];
  }
}

class ConsoleOutput extends LogOutput {
  @override
  void output(OutputEvent event) {
    for (var line in event.lines) {
      print(line);
    }
  }
}

class LoggerExps extends StatelessWidget {
  const LoggerExps({super.key});

  @override
  Widget build(BuildContext context) {

    // only show logs with level warning or above
    Logger.level = Level.warning;

    logger.t("Trace log");

    logger.d("Debug log");

    logger.i("Info log");

    logger.w("Warning log");

    logger.e("Error log", error: 'Test Error');

    logger.f("What a fatal log", error: 'error');

    return const Placeholder();
  }
}
